package com.wch.serverdemo.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wch.serverdemo.jdbc.DbContextHoldrer;
import com.wch.serverdemo.redis.IRedisDao;
import com.wch.serverdemo.service.UserService;

@Controller()
@RequestMapping("/test")
public class UserController {

	@Autowired
	private UserService userService;
	
	@Autowired
	private IRedisDao redisDao;
	
	@RequestMapping("/getUserInfo")
	@ResponseBody
	public String getUserInfo(String userName){
		
		//先默认从主库获取用户信息，然后再根据用户的区域信息匹配库
		DbContextHoldrer.setDbTypeByShardingId("792");
		String shardingId = userService.getShardingId(userName);
		DbContextHoldrer.setDbTypeByShardingId(shardingId);
		String password = userService.getUserInfo(userName);
		redisDao.saveInfo(userName, password);
		return redisDao.getInfo(userName);
		
	}
}
